<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <script src="layui/layui.js"></script>
</head>
<body>
<form class="layui-form" style="margin-top: 20px">
    <div class="layui-form-item">
        <label class="layui-form-label" style="width:200px;font-size: 25px;font-weight: bold;">物业名称</label>
        <div class="layui-input-block">
            <input type="text" style="height: 30px;width: 400px;font-size: 25px;" name="propertyname" id="property_name" required  lay-verify="required" placeholder="请输入物业名称" autocomplete="off" class="layui-input" value="${property.propertyname}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width:200px;font-size: 25px;font-weight: bold">物业编码</label>
        <div class="layui-input-inline">
            <input type="text" style="height: 30px;width: 400px;font-size: 25px;" name="propertycode" id="property_code" required lay-verify="required" placeholder="请输入物业编码" autocomplete="off" class="layui-input" value="${property.propertycode}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width:200px;font-size: 25px;font-weight: bold">负责人</label>
        <div class="layui-input-inline">
            <input type="text" style="height: 30px;width: 400px;font-size: 25px;" name="director" id="director" required lay-verify="required" placeholder="请输入负责人姓名" autocomplete="off" class="layui-input" value="${property.director}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width:200px;font-size: 25px;font-weight: bold">联系方式</label>
        <div class="layui-input-inline">
            <input type="text" style="height: 30px;width: 400px;font-size: 25px;" name="telphone" id="telphone" required lay-verify="required" placeholder="请输入联系方式" autocomplete="off" class="layui-input" value="${property.telphone}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width:200px;font-size: 25px;font-weight: bold">登录密码</label>
        <div class="layui-input-inline">
            <input type="text" style="height: 30px;width: 400px;font-size: 25px;" name="loginpassword" id="login_password" required lay-verify="required" placeholder="请输入物业的登录密码" autocomplete="off" class="layui-input" value="${property.loginpassword}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width:200px;font-size: 25px;font-weight: bold">物业地址</label>
        <div class="layui-input-inline">
            <input type="text" style="height: 30px;width: 400px;font-size: 25px;" name="propertyaddress" id="property_address" required lay-verify="required" placeholder="请输入物业地址" autocomplete="off" class="layui-input" value="${property.propertyaddress}">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label" style="width:200px;font-size: 25px;font-weight: bold">物业简介</label>
        <div class="layui-input-block">
            <textarea name="propertyindroduce" id="property_indroduce" style="height: 90px;width: 400px;font-size: 25px;" placeholder="请输入物业简介" class="layui-textarea">${property.propertyindroduce}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width:200px;font-size: 25px;font-weight: bold">
            <button type="button" name="file" class="layui-btn" lay-submit="uploadimg" id="test1">
                上传logo
            </button>
        </label>

        <div class="layui-input-inline" style="border: lightgray solid 1px;width: 200px;height: 200px;line-height: 200px">
            <img alt="" id="iamgepath" style="width: auto;height: auto;  max-width: 100%;  max-height: 100%;" src="/upload/${property.propertylogo}">
        </div>

    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" id="but" lay-submit lay-filter="formDemo">立即保存</button>
        </div>
    </div>
    <input type="text" name="id" id="id" value="${property.id}" style="display: none">
</form>
</body>

<script>
    var $=layui.$;

    $("#but").click(function () {
        var id=$("#id").val();
        var names=$("#property_name").val();
        var code=$("#property_code").val();
        var director=$("#director").val();
        var telphone=$("#telphone").val();
        var password=$("#login_password").val();
        var address=$("#property_address").val();
        var indroduce=$("#property_indroduce").val();
        var logo=$("#iamgepath").attr("src");
        console.log("简介"+indroduce);
        $.ajax({
            type: "POST",
            url: "/editbyid",
            data: {id:id, names:names,code:code,director:director,telphone:telphone,password:password,address:address,logo:logo,indroduce:indroduce},
            dataType: "text",
            success: function(data){
                layui.use('layer', function(){
                    var layer = layui.layer;
                    layer.msg('hello');
                });
                console.log("data="+data);
                if (data!=0){
                    layer.msg("修改成功");
                }else{
                    layer.msg("修改失败");
                }
            }
        });
    });

    layui.use('upload', function(){
        var upload = layui.upload;
        var uploadInst = upload.render({//执行实例
            elem: '#test1' //绑定元素
            ,accept:"images"
            ,url: '/addimage' //上传接口
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#iamgepath').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //上传完毕回调
                $("#iamgepath").attr("src","/upload/"+res.data.src);
                $("#imgpath").val(res.data.src);
                layer.msg("上传成功");
            }
            ,error: function(){
                //请求异常回调
                layer.msg("上传失败");
            }
        });
    });

    layui.use('form', function(){
        var form = layui.form;

        form.on('submit(uploadimg)',function(data){
            return false;
        });
    });

</script>

</html>